const copy = function(id){
	const input = document.createElement('input');
	document.body.appendChild(input);
	input.setAttribute('value', id);
	input.select();
	if (document.execCommand('copy')) {
		document.execCommand('copy');
		ELEMENT.Message.success('复制成功')
		//成功
	}else{
		ELEMENT.Message.error('复制失败')
		//失败
	}
	document.body.removeChild(input);
}

const go = function(url,id) {
	this.$router.push({
		path:url,
		query:{
			id:id
		}
	})
}


const openw = function(url,id) {
	window.open(url)
}

const cun = function(who,zhi){
  localStorage.setItem(who,zhi)
}

const back = function() {
	this.$router.go(-1)
}



import XLSX from 'xlsx';
import { read,utils } from 'xlsx'


const duwenjian = function(file){
  let files = file.file
  return new Promise((res, rej) => {
    var that = this;
    if (files.length <= 0) {
      return;
    }
    if (!/\.(xls|xlsx)$/.test(files.name.toLowerCase())) {
      ELEMENT.Message.error('上传格式不正确，请上传xls或者xlsx格式')
      return;
    }
    const fileReader = new FileReader();
    fileReader.onload = (ev) => {
      try {
        const data = ev.target.result;
        const workbook = read(data, {
          type: 'binary'
        });
        // 取第一张表
        const wsname = workbook.SheetNames[0];
        // 生成json表格内容
        const ws = utils.sheet_to_json(workbook.Sheets[wsname]);
        // 后续为自己对ws数据的处理
        res(ws)
      } catch (e) {
        return false;
        rej(e)
      }
    };
    fileReader.readAsBinaryString(files);
  })
}

export {copy,go,cun,openw,back,duwenjian}
